# cython: language_level=3

# 导入所需模块
import sys
from cpython cimport PyGILState_Ensure, PyGILState_Release,PyGILState_STATE

def call_python_function(const char* param_str):
    cdef PyGILState_STATE gstate
    gstate = PyGILState_Ensure()

    try:
        sys.path.append("/opt/arkime")
        # 导入 Python 模块
        module = __import__("test")
        # 获取 Python 函数
        func = getattr(module, "back_session_packet", None)
        if func:
            # 调用 Python 函数
            func(param_str.decode('utf-8'))
        else:
            raise AttributeError("Function 'back_session_packet' not found")
    except Exception as e:
        # 打印异常信息
        print("An error occurred:", e)
    finally:
        PyGILState_Release(gstate)
